﻿//========================================================================//
//      Copyright 2012, Smilodon Studio Inc.
//      All rights reserved.
//========================================================================//

/**
 *	ball
 *      @author: CYS
 */



var ball = function()
{
	this.x = 0;
	this.y = 0;
	this.vx = 1;
	this.vy = 1;
	this.c = new Color();
	this.c.setRGB(rnd(0.75), rnd(0.65), rnd(0.75));
	this.r = 150;
	this.life = 1;
	
}

ball.prototype.draw = function() 
{
	if(this.life <= 0) return;
	var col = this.c.getValue();
	//g2D.shadowColor   = col;
	g2D.fillStyle = col;
	//g2D.strokeStyle = col; 
	g2D.beginPath();
	g2D.arc(this.x, this.y, this.r, 0, 2*Math.PI, true );
	g2D.closePath();
	g2D.fill();
	
	g2D.stroke();
	
}

ball.prototype.go = function(t)
{
	this.vy += 0.3;
	this.x += this.vx;
	this.y += this.vy;
}

ball.prototype.isCol = function(mx, my)
{
	return this.r*this.r > dis2(this.x, this.y, mx, my);
}

ball.prototype.reBegin = function(width, height)
{
	this.x = -100 + rnd(-100); 
	this.y = height; 
	this.vx = 10+rnd(5);
	this.vy = -15-rnd(3);
	this.r = height*rndd(0.05, 0.1);
	this.life = 1;
}
